﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:local="clr-namespace:Danilins.Multitouch.Controls"
	xmlns:pl="clr-namespace:Danilins.Multitouch.PhysicsLibrary;assembly=Danilins.Multitouch.PhysicsLibrary">

	<ItemsPanelTemplate x:Key="canvasPanel">
		<Canvas/>
	</ItemsPanelTemplate>
	
	<Style TargetType="{x:Type local:MultitouchList}" BasedOn="{StaticResource {x:Type ItemsControl}}">
		<Setter Property="ItemsPanel" Value="{StaticResource canvasPanel}"/>
		<Setter Property="Template">
			<Setter.Value>
				<ControlTemplate TargetType="{x:Type local:MultitouchList}">
					<Border Background="{TemplateBinding Background}"
							BorderBrush="{TemplateBinding BorderBrush}"
							BorderThickness="{TemplateBinding BorderThickness}"
							Padding="{TemplateBinding Padding}"
							SnapsToDevicePixels="True">
						<pl:PhysicsController x:Name="Physics">
							<ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
						</pl:PhysicsController>
					</Border>
				</ControlTemplate>
			</Setter.Value>
		</Setter>
	</Style>

	<Style TargetType="{x:Type local:MultitouchListItem}">
		<Setter Property="pl:PhysicsController.EnablePhysics" Value="True"/>
		<Setter Property="pl:PhysicsController.IsCollidable" Value="False"/>

		<Setter Property="HorizontalContentAlignment" 
				Value="{Binding Path=HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
		<Setter Property="VerticalContentAlignment"
                Value="{Binding Path=VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
		<Setter Property="Template">
			<Setter.Value>
				<ControlTemplate TargetType="{x:Type local:MultitouchListItem}">
					<Border Background="{TemplateBinding Background}"
							BorderBrush="{TemplateBinding BorderBrush}"
							BorderThickness="{TemplateBinding BorderThickness}"
							Padding="{TemplateBinding Padding}"
							SnapsToDevicePixels="True">
						<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
										  VerticalAlignment="{TemplateBinding VerticalAlignment}"
										  SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
					</Border>
				</ControlTemplate>
			</Setter.Value>
		</Setter>
	</Style>
</ResourceDictionary>